package com.wangtao.firstapp.custom;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.wangtao.firstapp.R;

/**
 *
 * Created by lanouhn on 16/9/13.
 */
public class MyPopUpWindow extends PopupWindow {

    private TextView cancel, send;

    public  MyPopUpWindow(Context context, View.OnClickListener itemonClickListener) {
         super(context);

        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View view = layoutInflater.inflate(R.layout.popupwindow, null);

        cancel = (TextView) view.findViewById(R.id.cancel_popupwindow);//取消
        send = (TextView) view.findViewById(R.id.send_popupwindow);//发送

        cancel.setOnClickListener(itemonClickListener);
        send.setOnClickListener(itemonClickListener);


        //设置SelectPicPopupWindow的View
        this.setContentView(view);
        //设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
        //设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int height = view.findViewById(R.id.pop_layout_popupwindow).getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });

    }
}
